<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/** @var $this \Magento\Weee\Block\Renderer\Weee\Tax */
$data = ['fptAttribute' => [
    'region' => $this->helper('Magento\Core\Helper\Data')->jsonDecode(
        $this->helper('Magento\Directory\Helper\Data')->getRegionJson()
    ),
    'itemsData' => $this->getValues(),
    'bundlePriceType' => '#price_type',
]];
?>
<div id="attribute-<?php echo $this->getElement()->getHtmlId(); ?>-container" class="field"
     data-attribute-code="<?php echo $this->getElement()->getHtmlId(); ?>"
     data-mage-init="<?=$this->escapeHtml($this->helper('Magento\Core\Helper\Data')->jsonEncode($data))?>">
    <label class="label"><span><?php echo $this->getElement()->getLabel() ?></span></label>

    <div class="control">
        <table class="data-table" cellspacing="0">
            <thead>
                <tr>
                    <th class="col-website" <?php if (!$this->isMultiWebsites()): ?>style="display: none;"<?php endif; ?>><?php echo __('Website'); ?></th>
                    <th class="col-country required"><?php echo __('Country/State'); ?></th>
                    <th class="col-tax required"><?php echo __('Tax'); ?></th>
                    <th class="col-action"><?php echo __('Action'); ?></th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <td colspan="4" class="col-actions-add"><?php echo $this->getAddButtonHtml(); ?></td>
                </tr>
            </tfoot>
            <tbody data-role="fpt-item-container" class="fpt-item-container">
            </tbody>
        </table>
        <!--
            Hidden field below with attribute code id is necessary for jQuery validation plugin.
            Validation message will be displayed after this field.
        -->
        <input type="hidden" name="<?php echo $this->getElement()->getHtmlId(); ?>" id="<?php echo $this->getElement()->getHtmlId(); ?>" disabled="disabled">
    </div>

    <script data-role="row-template" type="text/x-jquery-tmpl">
        <tr id="<?php echo $this->getElement()->getHtmlId() ?>_weee_tax_row_${index}" data-role="fpt-item-row">
            <td class="col-website" <?php if (!$this->isMultiWebsites()): ?>style="display: none"<?php endif; ?>>
                <select name="<?php echo $this->getElement()->getName() ?>[${index}][website_id]"
                        class="<?php echo $this->getElement()->getClass() ?> website required-entry" data-role="select-website">
                    <?php foreach ($this->getWebsites() as $_websiteId => $_info): ?>
                    <option value="<?php echo $_websiteId ?>"><?php echo $_info['name'] ?><?php if (!empty($_info['currency'])): ?>[<?php echo $_info['currency'] ?>]<?php endif; ?></option>
                    <?php endforeach ?>
                </select>
            </td>
            <td class="col-country">
                <select id="<?php echo $this->getElement()->getName() ?>_weee_tax_row_${index}_country"
                        name="<?php echo $this->getElement()->getName() ?>[${index}][country]"
                        class="<?php echo $this->getElement()->getClass() ?> country required-entry" data-role="select-country">
                    <?php foreach ($this->getCountries() as $_country): ?>
                    <option value="<?php echo $_country['value'] ?>"><?php echo htmlspecialchars($_country['label']) ?></option>
                    <?php endforeach ?>
                </select>
                <select id="<?php echo $this->getElement()->getName() ?>_weee_tax_row_${index}_state"
                        name="<?php echo $this->getElement()->getName() ?>[${index}][state]"
                        class="<?php echo $this->getElement()->getClass() ?> state" disabled="" data-role="select-state">
                    <option value="0">*</option>
                </select>
            </td>
            <td class="col-tax">
                <input name="<?php echo $this->getElement()->getName() ?>[${index}][price]"
                       class="<?php echo $this->getElement()->getClass() ?> required-entry validate-greater-than-zero"
                       type="text" value="${value}"/>
            </td>
            <td class="col-action">
                <input name="<?php echo $this->getElement()->getName() ?>[${index}][delete]" class="delete" type="hidden" value="" data-role="delete-fpt-item"/>
                <?php echo $this->getChildHtml('delete_button') ?>
            </td>
        </tr>
    </script>
</div>
